package com.example.backend.service.impl;

import com.example.backend.entity.Company;
import com.example.backend.entity.Warehouse;
import com.example.backend.entity.Port;
import com.example.backend.dto.CompanyPortInfo;
import com.example.backend.mapper.CompanyMapper;
import com.example.backend.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public int addCompany(Company company) {
        return companyMapper.insert(company);
    }

    @Override
    public Company getCompanyById(Long id) {
        return companyMapper.selectById(id);
    }

    @Override
    public List<Company> getAllCompanies() {
        return companyMapper.selectAll();
    }

    @Override
    public int updateCompany(Company company) {
        return companyMapper.update(company);
    }

    @Override
    public int deleteCompany(Long id) {
        return companyMapper.deleteById(id);
    }

    @Override
    public List<Company> getCompaniesByPortId(Long portId) {
        return companyMapper.selectByPortId(portId);
    }

    @Override
    public List<CompanyPortInfo> getCompaniesWithRemainingWeightByPortId(Long portId) {
        return companyMapper.selectCompaniesWithRemainingWeightByPortId(portId);
    }

    @Override
    public List<CompanyPortInfo> getCompaniesByPortIdSimple(Long portId) {
        return companyMapper.selectCompaniesByPortIdSimple(portId);
    }

    @Override
    public List<Warehouse> getWarehousesByCompanyId(Long companyId) {
        return companyMapper.selectWarehousesByCompanyId(companyId);
    }

    @Override
    public int addCompanyWarehouse(Long companyId, Long warehouseId) {
        return companyMapper.insertCompanyWarehouse(companyId, warehouseId);
    }

    @Override
    public int removeCompanyWarehouse(Long companyId, Long warehouseId) {
        return companyMapper.deleteCompanyWarehouse(companyId, warehouseId);
    }

    @Override
    public List<Port> getPortsByCompanyId(Long companyId) {
        return companyMapper.selectPortsByCompanyId(companyId);
    }

    @Override
    public int addCompanyPort(Long companyId, Long portId) {
        return companyMapper.insertCompanyPort(companyId, portId);
    }

    @Override
    public int removeCompanyPort(Long companyId, Long portId) {
        return companyMapper.deleteCompanyPort(companyId, portId);
    }

    @Override
    public List<CompanyPortInfo> getPortsWithRemainingByCompanyId(Long companyId) {
        return companyMapper.selectPortsWithRemainingByCompanyId(companyId);
    }
} 